package com.tianhua.javs.client.bean;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 * date: 2022/2/13
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Data
public class TranslateResultBean {
    /**
     * 转换后的代码段
     */
    private String segment;

    /**
     * 当前转换代码的内容需要导入的包
     */
    private List<String> packageList = new ArrayList<>();


    /**
     * 转换后的代码可能代表的变量类型
     * 主要赋值语句可能需要
     */
    private String segmentClass;

    /**
     * 一次函数匹配过程中的全部匹配结果，这里主要是缓存或者帮助调试
     */
    private JavsSegmentBean matchSegmentBean;

    /**
     * 在进行解析过程中进行打标判断是否匹配了某次函数解析替换
     */
    private boolean match;

    public TranslateResultBean(){}

    public TranslateResultBean(String segment){
        this.segment = segment;
    }

    public TranslateResultBean(String segment, Boolean match){
        this.segment = segment;
        this.match = match;
    }


    public static TranslateResultBean getInstance(String segment){
        return new TranslateResultBean(segment);
    }

    public static TranslateResultBean getInstance(String segment,Boolean match){
        return new TranslateResultBean(segment, match);
    }

    /**
     * 将脚本段转换为解析结果bean
     * @param javsSegmentBean
     * @return
     */
    public static TranslateResultBean getInstance(JavsSegmentBean javsSegmentBean){
        if(javsSegmentBean == null || !javsSegmentBean.match()){
            return null;
        }
        TranslateResultBean translateResultBean = TranslateResultBean.getInstance(javsSegmentBean.getSegment());
        translateResultBean.setPackageList(javsSegmentBean.getPackageList());
        translateResultBean.setSegmentClass(javsSegmentBean.getSegmentClass());
        translateResultBean.setMatchSegmentBean(javsSegmentBean);

        return translateResultBean;
    }

}
